// MainHtmlView.cpp : implementation file
//

#include "stdafx.h"
#include "kwclientcore.h"
#include "MainHtmlView.h"
#include "ClientConfiguration.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMainHtmlView

IMPLEMENT_DYNCREATE(CMainHtmlView, CHtmlView)

CMainHtmlView::CMainHtmlView()
{
	//{{AFX_DATA_INIT(CMainHtmlView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

CMainHtmlView::~CMainHtmlView()
{
}

void CMainHtmlView::DoDataExchange(CDataExchange* pDX)
{
	CHtmlView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMainHtmlView)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMainHtmlView, CHtmlView)
	//{{AFX_MSG_MAP(CMainHtmlView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMainHtmlView diagnostics

#ifdef _DEBUG
void CMainHtmlView::AssertValid() const
{
	CHtmlView::AssertValid();
}

void CMainHtmlView::Dump(CDumpContext& dc) const
{
	CHtmlView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainHtmlView message handlers

void CMainHtmlView::OnInitialUpdate() 
{
	//TODO: This code navigates to a popular spot on the web.
	//Change the code to go where you'd like.
	//Navigate2(_T("http://www.microsoft.com/visualc/"), NULL, NULL);
  UpdateView();
}

void CMainHtmlView::UpdateView()
{
  CString str = ClientConfiguration::Instance()->m_Options.m_szHomePageURL;
  str.MakeLower();

  CString strUrl;
  int nIndex = str.Find("_kwsystemserver");
  if (nIndex != -1)
  {
    strUrl = str.Left(nIndex);
    strUrl += ClientConfiguration::Instance()->m_strServerIPAddress.c_str();
    strUrl += str.Right(str.GetLength()-nIndex-strlen("_kwsystemserver"));
  }
  else
  {
    strUrl = str;
  }
  Navigate2(_T(strUrl), NULL, NULL);
}
